package com.one.group.admin.service.impl;

import com.mybatisflex.core.service.IService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.one.group.admin.mapper.DecorationChargeMapper;
import com.one.group.model.entity.DecorationCharge;
import com.one.group.service.DecorationChargeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @author kld
 * @description 装修收费关联表服务实现
 */
@Service
public class DecorationChargeServiceImpl extends ServiceImpl<DecorationChargeMapper, DecorationCharge> implements DecorationChargeService {

    @Autowired
    private DecorationChargeMapper decorationChargeMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveDecorationCharge(DecorationCharge decorationCharge) {
        if (decorationCharge == null) {
            return false;
        }
        
        // 设置创建时间和更新时间
        Date now = new Date();
        decorationCharge.setCreateTime(now);
        decorationCharge.setUpdateTime(now);
        
        return decorationChargeMapper.insert(decorationCharge) > 0;
    }
    
    @Override
    public List<DecorationCharge> findByDecorationId(Long decorationId) {
        if (decorationId == null) {
            return List.of();
        }
        return decorationChargeMapper.findByDecorationId(decorationId);
    }
}